/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import java.util.List;

import e.odbo.DB;
import e.odbo.data.dao.InfoDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.sentence.PreparedSentence;
import com.openbravo.data.loader.sqlbuilder.QBFBuilder;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteBasic;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteString;
import com.openbravo.data.loader.sentence.StaticSentence;
import com.openbravo.bean.infobean.CustomerInfo;

/**
 *
 * @author Administrator
 */
public class CustomerInfoDAO extends InfoDAO<CustomerInfo,CustomerDAO>{
 
    public CustomerInfoDAO(CustomerDAO base) {
         super(base,new int[]{0,1,2,3});
    }

    public CustomerInfo readValues(DataRead dr,CustomerInfo c) throws BasicException {
        if(c==null)
        	c = new CustomerInfo();
                        c.setKey(dr.getString(1));
                        c.setTaxid(dr.getString(2));
                        c.setSearchkey(dr.getString(3));
                        c.setName(dr.getString(4));
        return c;
    }

    public CustomerInfo findCustomerInfoByCard(String card) throws BasicException{
        return (CustomerInfo)new PreparedSentence(s
                , DB.getListSQL(base,columnIndexs)+" WHERE CARD = ? AND VISIBLE = " + s.getDialect().TRUE()
                , SerializerWriteString.INSTANCE
                , this).find(card);
    }

     public CustomerInfo findCustomerInfoByID(String id) throws BasicException{
        return (CustomerInfo)new PreparedSentence(s
                , DB.getListSQL(base,columnIndexs)+" WHERE ID = ? AND VISIBLE = " + s.getDialect().TRUE()
                , SerializerWriteString.INSTANCE
                ,this).find(id);
    }

    @Override
    public Class getSuportClass() {
        return CustomerInfo.class;
    }

	public CustomerInfo findCustomerInfoByNumberAndPass(String number,
			String pass) throws BasicException {
		return (CustomerInfo)new PreparedSentence(s
	            , DB.getListSQL(base,columnIndexs)+" WHERE TAXID = ? AND APPPASSWORD = ? AND VISIBLE = " + s.getDialect().TRUE()
	            , new SerializerWriteBasic(new Datas[] {Datas.STRING, Datas.STRING})
	            , this).find(new Object[]{number,pass});
	}


	public List<CustomerInfo> list(Object filter) throws BasicException {
		return  new StaticSentence(s
	            , new QBFBuilder(DB.getListSQL(base,columnIndexs)+" WHERE VISIBLE = " + s.getDialect().TRUE() + " AND ?(QBF_FILTER) ORDER BY NAME", new String[] {"TAXID", "SEARCHKEY", "NAME","CATEGORY"})
        , new SerializerWriteBasic(new Datas[] {Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING,Datas.OBJECT, Datas.STRING})
        ,this).list(filter);
	}

}
